package com.sukaiyi.giteeideaplugin.setting;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.util.xmlb.XmlSerializerUtil;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@State(name = "GiteePluginForIdea", storages = {@com.intellij.openapi.components.Storage(value = "$APP_CONFIG$/GiteePluginForIdea.xml")})
public class PluginSetting implements PersistentStateComponent<PluginSetting> {

    @Getter
    @Setter
    private String giteeAccessToken;
    @Getter
    @Setter
    private String defaultClonePath;
    @Getter
    @Setter
    private String defaultProtocol = "ssh";
    @Setter
    @Getter
    private String gitExecutablePath = "git";

    @Nullable
    @Override
    public PluginSetting getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull PluginSetting pluginSetting) {
        XmlSerializerUtil.copyBean(pluginSetting, this);
    }

    public static PluginSetting getInstance() {
        return ServiceManager.getService(PluginSetting.class);
    }
}
